package panel.viewSpots.navigation
{
	import assists.HtmlText;
	import assists.TextFieldUtils;
	import assists.resource.ResourceLoader;
	
	import flash.display.Bitmap;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.text.TextField;
	
	public class ArrowItem extends Sprite
	{
		private var _data:Object;
		private var _label:TextField;
		private var _loader:ResourceLoader;
		private var _arrowImage:Sprite = new Sprite();
		private var _currentPlaceID:int;
		private var _nameShape:Shape = new Shape();
		private var _nameTxt:TextField = new TextField();
		private var _isCurrentPos:Boolean = false;
		public function ArrowItem(loader:ResourceLoader)
		{
			_loader = loader;
			
		}
		
		private function init():void
		{
			_nameTxt.mouseEnabled = false;
			_nameTxt.autoSize = "left";
			var preStr:String = "";
			if(_data.openStartTime != "")
			{
				_arrowImage.addChild(new _loader.uiManager.arrowRedPng());
				preStr = "\n<font color='#ff0000'>限时开放</font>";
				
			}else if(_currentPlaceID == _data.id)
			{
				_arrowImage.addChild(new _loader.uiManager.arrowYellowPng());	
				preStr = "\n<font color='#fff100'>(当前位置)</font>";
				_isCurrentPos = true;
			}
			else
			{
			_arrowImage.addChild(new _loader.uiManager.arrowGreenPng());
			}
			_arrowImage.scaleX = _arrowImage.scaleY = 0.5;
			_arrowImage.x = - _arrowImage.width * 0.5;
			_arrowImage.y = - _arrowImage.height;
			this.addChild(_arrowImage);
			
			_label = new TextField();
			_label.autoSize = "left";
			_label.mouseEnabled = false;
			this.addChild(_label);
			
			TextFieldUtils.setHtmlText(_nameTxt,HtmlText.formatSizeColor(_data.name + preStr,0xffffff));
			_nameTxt.x = - _nameTxt.width * 0.5;
			
			drawNameShape();
			
			this.addChild(_nameShape);
			this.addChild(_nameTxt);
		}
		
		public function changeLabelVisible(value:Boolean):void
		{
			_nameShape.visible = value;
			_nameTxt.visible = value;
		}
		
		public function set label(value:String):void
		{
			TextFieldUtils.setHtmlText(_label,HtmlText.formatSizeColor(value,0xffffff,20));
			resize();
		}
		
		public function set data(value:Object):void
		{
			_data = value;
			init();
		}
		
		public function isVisited(value:Boolean):void
		{
			if(value && _data.openStartTime == "")
			{
				if(_currentPlaceID == _data.id)
				{
					_isCurrentPos = true;
					TextFieldUtils.setHtmlText(_nameTxt,HtmlText.formatSizeColor(_data.name + "\n<font color='#fff100'>(当前位置)</font>",0xffffff));
					drawNameShape();
				}else
				{
					if(_isCurrentPos)
					{
					TextFieldUtils.setHtmlText(_nameTxt,HtmlText.formatSizeColor(_data.name,0xffffff));
						drawNameShape();
					_isCurrentPos = false;
					}
				}
				_arrowImage.removeChildren();
				_arrowImage.addChild(new _loader.uiManager.arrowYellowPng());	
			}
		}
		
		private function drawNameShape():void
		{
			_nameShape.graphics.clear();
			_nameShape.graphics.beginFill(0,0.7);
			_nameShape.graphics.drawRoundRect(_nameTxt.x,0,_nameTxt.width,_nameTxt.height,4,4);
			_nameShape.graphics.endFill();
		}
		
		public function set currentPlaceID(value:int):void
		{
			_currentPlaceID = value;
		}
		
		override public function get height():Number
		{
			return _arrowImage.height;
		}
		
		public function get data():Object
		{
			return _data;
		}
		
		private function resize():void
		{
			_label.x = _arrowImage.x + (_arrowImage.width - _label.width)* 0.5;
			_label.y = _arrowImage.y + _arrowImage.height * 0.12;
		}
		
	}
}